package org.ccnetconfig.ccdroid;

import java.util.LinkedList;

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;

public class CCDroid extends ExpandableListActivity {
	private ExpandableListView	list		= null;
	private DataProvider				sqlite	= null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate ( Bundle savedInstanceState ) {
		super.onCreate ( savedInstanceState );
		setDefaultKeyMode ( DEFAULT_KEYS_SHORTCUT );

		this.list = getExpandableListView ();
		sqlite = new DataProvider ( this );
		this.list.setChoiceMode ( ExpandableListView.CHOICE_MODE_SINGLE );

		LinkedList<Settings> allSettings = sqlite.getAllSettings ( null );

		if ( allSettings.isEmpty () ) {
			Settings s = new Settings ( "ccnet.ccnetconfig.org" );
			allSettings.add ( s );
			sqlite.insertSettings ( null, s );
		}

		this.setListAdapter ( (ExpandableListAdapter) new SettingsAdapter ( this, allSettings ) );

	}

	@Override
	public void onCreateContextMenu ( ContextMenu menu, View v, ContextMenuInfo menuInfo ) {
		menu.setHeaderTitle ( "Add Server" );
		menu.add ( 0, 1, 0, "Add Server" );
		menu.add ( 0, 2, 0, "Edit Server" );
	}
}